# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

pkgname=scons
pkgver=2.4.1
pkgrel=1
pkgdesc="Extensible Python-based build utility"
arch=('any')
groups=('base-devel')
url="http://scons.org"
license=('MIT')
depends=('python2')
source=("http://downloads.sourceforge.net/sourceforge/$pkgname/$pkgname-$pkgver.tar.gz"
        scons-2.3.4-cyglink-msys2.patch
        scons-2.3.4-msys2-plat-mingw-env.patch
        mingw_w64.py)
md5sums=('9a0ddf33d9839f04380e0fae87cc4b40'
         'c0ef2aa52976ed869357d625cd75b702'
         '4eb3a62a2fff6cac1cccd45a21cbcd8a'
         '7f2e8590c45e17a927f861051fc762b1')

prepare() {
  cd "$srcdir/$pkgname-$pkgver"
  cp ../mingw_w64.py engine/SCons/Tool/

  # avoid errors when re-running makepkg
  rm -f engine/SCons/Platform/msys.py engine/SCons/Tool/msyslink.py
  patch -p1 -i ${srcdir}/scons-2.3.4-cyglink-msys2.patch
  patch -p0 -i ${srcdir}/scons-2.3.4-msys2-plat-mingw-env.patch
}

package() {
  cd "$srcdir/$pkgname-$pkgver"

  /bin/python2 setup.py install \
      --standard-lib \
      --prefix=/usr \
      --install-data=/usr/share \
      --optimize=1 \
      --root="$pkgdir"

  # fix for python 2.7
  sed -i 's:^#!.*bin/env python:#!/usr/bin/python2:' \
    "$pkgdir"/usr/bin/*

  install -Dm644 LICENSE.txt \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
